<template>
	<view class="pages-technician">
		<!-- #ifndef H5 -->
		<uni-nav-bar :fixed="true" :shadow="false" :statusBar="true" title="接单池" leftIcon="" color="#ffffff"
			:backgroundColor="primaryColor">
		</uni-nav-bar>
		<view :style="{height:`${configInfo.navBarHeight}px`}"></view>
		<fixed :top="configInfo.navBarHeight">
		<!-- #endif -->
			<!-- #ifdef H5 -->
			<fixed>
			<!-- #endif -->
				<view class="fill-base">
					<view class="flex-center pl-lg pr-lg pt-md pb-md">
						<view class="flex-1 pr-md flex-y-center" @tap="chooseLocation">
							<i class="iconfont iconxiangdaodaoda" :style="{color:primaryColor}"></i>
							<view class="f-paragraph ellipsis flex-1 max-600 pl-sm">{{location.address || '未知'}}</view>
						</view>
						<i class="iconfont icon-right text-bold" style="font-size: 13px;"></i>
						<!-- <view class="f-paragraph c-title">全部订单</view> -->
					</view>
					<view class="flex-between pl-lg pr-lg pb-sm">
						<view class="flex-center" @tap="handerTypeChange"> <!--configInfo.plugAuth.demand-->
							<view class="rel">
								<text class="pr-sm text-bold">新订单</text>
								<text class="abs count-number flex-center fill-warning c-base f-little"
									v-if="allCount && (allCount.service_count + allCount.demand_count)">{{allCount.service_count + allCount.demand_count}}</text>
							</view>
							<i class="iconfont iconshaixuan1" style="color: #999;font-size: 18px;"></i>
						</view>
						<view class="flex-center" @tap="changeWork">
							<text class="f-caption pr-sm c-paragraph">接单开关</text>
							<i class="iconfont icon-switch" style="font-size: 40px;"
								:class="[{'icon-switch-on':coachInfo.is_work==1}]"
								:style="{color:coachInfo.is_work==1? primaryColor:'#f2f2f2'}"></i>
						</view>
					</view>
					<!-- <view class="">
					<tab @change="handerTabChange" v-if="orderTypeIndex == 1" :list="tabList" :activeIndex="activeIndex*1" :activeColor="primaryColor"
						:width="100/tabList.length + '%'" height="100rpx"></tab>
					<tab @change="handerTabChange" v-if="orderTypeIndex == 2" :list="demandTabList" :activeIndex="activeIndex*1" :activeColor="primaryColor"
						:width="100/demandTabList.length + '%'" height="100rpx"></tab>
					<view class="b-1px-b"></view>
				</view> -->
				</view>
			</fixed>

			<block v-if="isLoad && coachInfo.is_work == 0">
				<abnor type="DATA">
				</abnor>
			</block>
			<block v-if="isLoad && coachInfo.is_work == 1">
				<view class="mt-md ml-md mr-md fill-base radius-16 pd-lg" v-for="(item,index) in list.data" :key="index"
					@tap="goDetail(item.id)">
					<block v-if="orderTypeIndex == 1">
						<view class="flex-between">
							<view class="flex-center">
								<text class="f-mini-title text-bold">{{item.order_type == 1 ? '上门服务' : '上门回收'}} </text>
								<text class="f-mini-title c-paragraph">（{{item.coach_id ? '系统派单' : '抢单'}}）</text>
							</view>
							<text class="f-title text-bold">距离：{{item.distance | handledDistance}}km</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">上门时间：</text>
							<text
								class="flex-1 f-sm-title c-warning">{{$util.formatTime(item.start_time*1000, 'YY-M-D h:m')}}</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">服务名称：</text>
							<text class="flex-1 f-mini-title c-paragraph">{{item.order_goods[0].name}}</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">服务价格：</text>
							<text class="flex-1 f-sm-title c-warning">￥{{item.order_goods[0].price}}</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">服务内容：</text>
							<text class="flex-1 f-mini-title c-paragraph">{{item.order_goods[0].title}}</text>
						</view>
						<!-- 		<view class="flex-y-center pt-md text-bold">
					<text class="f-title c-title order-name">服务地址：</text>
					<text class="flex-1 f-sm-title c-warning">{{item.address_info.address}}</text>
				</view> -->
						<view class="flex-y-center pt-md text-bold">
							<text class="f-title c-title order-name">服务地址：</text>
							<view class="flex-1 flex-center">
								<text
									class="flex-1 f-mini-title c-paragraph pre-wrap">{{item.address_info.address}}</text>
								<view class="locationContainer" @click.stop="mapNavigaion(item.address_info.address)">
									<image class="location" src="/static/images/location.png" mode="aspectFit"></image>
									<text :style="{color:primaryColor}">导航</text>
								</view>

							</view>
						</view>


						<view class="flex-center pt-md text-bold" v-if="item.text">
							<text class="f-title c-title order-name">服务备注：</text>
							<text class="flex-1 f-mini-title c-paragraph pre-wrap">{{item.text}}</text>
						</view>
					</block>
					<!--需求订单-->
					<block v-if="orderTypeIndex == 2">
						<view class="flex-between">
							<view class="flex-center">
								<text class="f-title text-bold">{{typeObject[item.type]}} </text>
								<text class="f-mini-title c-paragraph">（{{item.coach_id ? '系统派单' : '抢单'}}）</text>
								<text class="f-mini-title text-bold"
									:style="{color: primaryColor}">{{item.type == 1 ? '订金' : '全款'}}</text>
							</view>
							<text class="f-title text-bold">距离：{{item.distance | handledDistance}}km</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">上门时间：</text>
							<text
								class="flex-1 f-sm-title c-warning">{{$util.formatTime(item.start_time*1000, 'YY-M-D h:m')}}</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">服务类别：</text>
							<text class="flex-1 f-mini-title c-paragraph">{{item.f_type + '/' + item.s_type}}</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">服务名称：</text>
							<text class="flex-1 f-mini-title c-paragraph">{{item.title}}</text>
						</view>
						<view class="flex-center pt-md text-bold">
							<text class="f-title c-title order-name">服务价格：</text>
							<text class="flex-1 f-sm-title c-warning">￥{{item.price}}</text>
						</view>
						<view class="flex-center pt-md text-bold" v-if="item.introduce">
							<text class="f-title c-title order-name">服务内容：</text>
							<text class="flex-1 f-mini-title c-paragraph">{{item.introduce}}</text>
						</view>
						<!-- <view class="flex-y-center pt-md text-bold">
					<text class="f-title c-title order-name">服务地址：</text>
					<text class="flex-1 f-sm-title c-warning">{{item.address}}</text>
				</view> -->
						<view class="flex-y-center pt-md text-bold">
							<text class="f-title c-title order-name">服务地址：</text>
							<view class="flex-1 flex-center">
								<text class="flex-1 f-mini-title c-paragraph pre-wrap">{{item.address}}</text>
								<view class="locationContainer" @click.stop="mapNavigaion(item.address)">
									<image class="location" src="/static/images/location.png" mode="aspectFit"></image>
									<text :style="{color:primaryColor}">导航</text>
								</view>

							</view>
						</view>


					</block>
					<view class="flex-center pt-lg">
						<view class="flex-center order-btn radius-10 f-title c-base fill-warning"
							@tap.stop="refuseOrder(item)" v-if="item.coach_id">拒绝接单</view>
						<view class="flex-center order-btn radius-10 f-title ml-lg c-base"
							@tap.stop="$util.goUrl({url: `/user/pages/pool/assign?id=${item.id}&type=${orderTypeIndex}&s_type=${orderTypeIndex == 2 ? item.s_type_id : item.order_goods[0].s_type}`})"
							v-if="[1,2].includes(coachInfo.identity) && coachInfo.company_id"
							:style="{background: primaryColor}">指派</view>
						<view class="flex-center order-btn radius-10 f-title ml-lg c-base"
							:style="{background: primaryColor}" @tap.stop="orderChange(index)">确认接单</view>
					</view>
				</view>

				<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading"
					v-if="loading">
				</load-more>
				<block v-if="!loading&&list.data.length<=0&&list.current_page==1">
					<abnor v-if="location.lat&&location.lng">
					</abnor>
					<block v-if="!location.lat&&!location.lng">
						<!-- #ifdef H5 -->
						<abnor type="NOT_LOCATION" title="暂无数据"></abnor>
						<!-- #endif -->
						<!-- #ifndef H5 -->
						<abnor type="NOT_LOCATION" title="暂无数据" @confirm="toOpenLocation"
							:button="[{ text: '开启定位' , type: 'confirm' }]" btnSize=""></abnor>
						<!-- #endif -->
					</block>
				</block>
				<view class="space-footer"></view>
			</block>

			<!--订单类型-->
			<w-picker mode="selector" :options="orderType" :themeColor="primaryColor" :visible.sync="showOrderType"
				@confirm="selectConfirm($event , 'ordertype')">
			</w-picker>
			<!--附近排序-->
			<w-picker mode="selector" :options="distanceList" :themeColor="primaryColor" :visible.sync="showDistance"
				@confirm="selectConfirm($event , 'di_order')">
			</w-picker>
			<!--服务分类-->
			<w-picker mode="linkage" :options="skill" :themeColor="primaryColor" :level="2" defaultType="name"
				:visible.sync="showServer" @confirm="selectConfirm($event , 'type')" :defaultProps="serverProps">
			</w-picker>
			<!--价格区间-->
			<w-picker mode="selector" :options="priceList" :themeColor="primaryColor" :visible.sync="showPrice"
				@confirm="selectConfirm($event , 'pr_order')">
			</w-picker>
			<!--订单类型-->
			<w-picker mode="selector" :options="demandOrder" :themeColor="primaryColor" :visible.sync="showDemand"
				@confirm="selectConfirm($event , 'order_type')">
			</w-picker>

			<uni-popup ref="screen_all" type="bottom">
				<view @touchmove.stop.prevent class="fill-base pl-lg pr-lg common-popup-content"
					style="width: 100%;border-radius: 34rpx 34rpx 0 0;">
					<view class="all-title w-100 flex-center pb-lg rel">
						<text class="f-title text-bold">筛选</text>
						<i class="iconfont icon-add rotate-45 text-bold abs" style="right: 0;top: 0;"
							@tap="$refs.screen_all.close()"></i>
					</view>
					<view class="w-100 flex pb-lg">
						<view class="flex-between order-type radius-10" :style="{borderColor: primaryColor}"
							v-if="configInfo.plugAuth.demand">
							<view class="order-type-item pl-md pr-md pt-sm pb-sm f-caption rel"
								v-for="(item,index) in orderType" :key="index" @tap="changeType(item.value)"
								:style="{background: params.orderTypeIndex == item.value ? primaryColor : '', color: params.orderTypeIndex == item.value ? '#fff' : '#333'}">
								{{item.label}}
								<text class="abs count-number flex-center fill-warning c-base f-little"
									v-if="allCount[item.type]">{{allCount[item.type]}}</text>
							</view>
						</view>
					</view>
					<view class="sex-box w-100">
						<view class="sex-title f-paragraph text-bold">距离</view>
						<view class="flex-warp pt-lg">
							<view class="type-item mr-md flex-center f-desc pl-md pr-md"
								:style="{backgroundColor: params.di_order == item.value ? primaryColor: '',borderColor: params.di_order == item.value ? primaryColor : '#ddd',color: params.di_order == item.value ? '#fff' : '#778498'}"
								v-for="(item,index) in distanceList" :key="index"
								@tap="checkConfirm(item.value, 'di_order')">{{item.label}}</view>
						</view>
					</view>
					<view class="sex-box w-100">
						<view class="sex-title f-paragraph text-bold pt-lg">服务类型</view>
						<view class="pt-lg">
							<scroll-view scroll-y :scroll-with-animation="true" lower-threshold="100"
								style="width: 100%;max-height: 20vh;">
								<view class="flex-warp">
									<block v-for="(p,i) in skill" :key="i">
										<block v-if="p.children">
											<view @tap.stop="checkConfirm(item.id, 'type')"
												class="flex-center mr-md f-desc type-item pl-md pr-md mb-md"
												:style="{backgroundColor: params.type == item.id ? primaryColor: '', borderColor: params.type == item.id ? primaryColor : '#ddd',color: params.type == item.id ? '#fff' : '#778498'}"
												v-for="(item,index) in p.children" :key="index">
												{{item.name}}
											</view>
										</block>
									</block>
								</view>
							</scroll-view>
						</view>
					</view>
					<view class="sex-box w-100">
						<view class="sex-title f-paragraph text-bold">价格</view>
						<view class="flex-warp pt-lg">
							<view class="type-item mr-md flex-center f-desc pl-md pr-md"
								:style="{backgroundColor: params.pr_order == item.value ? primaryColor: '',borderColor: params.pr_order == item.value ? primaryColor : '#ddd',color: params.pr_order == item.value ? '#fff' : '#778498'}"
								v-for="(item,index) in priceList" :key="index"
								@tap="checkConfirm(item.value, 'pr_order')">{{item.label}}</view>
						</view>
					</view>
					<view class="w-100 pt-lg" v-if="params.orderTypeIndex == 2">
						<view class="sex-title f-paragraph text-bold">订单类型</view>
						<view class="flex-warp pt-lg">
							<view class="type-item mr-md flex-center f-desc pl-md pr-md"
								:style="{backgroundColor: params.order_type == item.value ? primaryColor: '',borderColor: params.order_type == item.value ? primaryColor : '#ddd',color: params.order_type == item.value ? '#fff' : '#778498'}"
								v-for="(item,index) in demandOrder" :key="index"
								@tap="checkConfirm(item.value, 'order_type')">{{item.label}}</view>
						</view>
					</view>
					<view class="button">
						<view @tap.stop="toReset" class="item-child">
							重置
						</view>
						<view @tap.stop="toConfirm" class="item-child" :style="{background: primaryColor,color:'#fff'}">
							确定
						</view>
					</view>
					<view class="space-safe"></view>
				</view>
			</uni-popup>

			<!-- #ifdef APP-PLUS -->
			<block v-if="isLoad">
				<open-location-info ref="open_location_info" :pageActive="pageActive" :home="true"></open-location-info>
			</block>
			<!-- <openAuth type="location" ref="app_check_item"></openAuth> -->
			<!-- #endif -->

			<view :style="{height: `${configInfo.tabbarHeight}px`}"></view>
			<tabbar :cur="2"></tabbar>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import siteInfo from '@/siteinfo.js';
	import tabbar from "@/components/tabbar.vue"
	import openAuth from "@/components/open-auth.vue"


	export default {
		components: {
			tabbar,
			openAuth
		},
		data() {
			return {
				showDistance: false,
				showServer: false,
				showPrice: false,
				showOrderType: false,
				showDemand: false,
				serverProps: {
					label: "name",
					value: "id",
					children: "children"
				},
				isLoad: false,
				loading: true,
				typeObject: {
					1: '咨询单',
					2: '一口价',
					3: '家政公司'
				},
				checkSkill: {
					pInd: 0,
					ind: 0
				},
				params: {
					di_order: 0, // 1距离近 2距离远
					pr_order: 0, // 1价格高 2价格低
					type: 0,
					order_type: 0,
					orderTypeIndex: 1
				},
				allCount: ''
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			tabList: state => state.pool.tabList,
			activeIndex: state => state.pool.activeIndex,
			distanceList: state => state.pool.distanceList,
			skill: state => state.pool.skill,
			priceList: state => state.pool.priceList,
			param: state => state.pool.param,
			list: state => state.pool.list,
			pageActive: state => state.pool.pageActive,
			orderType: state => state.pool.orderType,
			location: state => state.user.location,
			coachInfo: state => state.user.coachInfo,
			orderTypeIndex: state => state.pool.orderTypeIndex,
			demandTabList: state => state.pool.demandTabList,
			demandOrder: state => state.pool.demandOrder,
		}),
		filters: {
			handledDistance(val) {
				return val > 0 ? (val / 1000).toFixed(2) : val
			}
		},
		async onLoad(options) {
			this.initIndex()
		},
		async onShow() {
			this.getAcceptCount()
			if (!this.location.lat && this.pageActive) {
				this.toResetUtilLoca()
			}
		},
		async onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh();
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.loading = true;
			this.getList(this.param.page + 1);
		},
		methods: {
			...mapActions(['getConfigInfo', 'getTypeList', 'getWaitOrderList', 'getCoachInfo']),
			...mapMutations(['updatePoolItem', 'updateHomeItem', 'updateUserItem']),
			async initIndex(refresh = false) {
				if (!this.configInfo.id || refresh) {
					await this.getConfigInfo()
				}
				if (!this.coachInfo.id || refresh) {
					await this.getCoachInfo()
				}
				// if(this.pageActive && !refresh){
				// 	this.$util.hideAll()
				// 	this.isLoad = true
				// 	this.loading = false
				// 	return
				// }
				await this.getTypeList()
				this.isLoad = true
				// this.$util.isCheckAuth({type: 'location'}).then(res => {
				// 	console.log(res ,'========> res')
				// 	if(res){
				// 		this.$refs.app_check_item.open()
				// 	}
				// })
				let {
					lng = 0,
						lat = 0,
						address = ''
				} = await this.$util.getUtilLocation(true)
				if (!address) {
					console.log(this.location, '========> 通过key获取地理位置')
					await this.$util.getMapInfo()
				}
				this.updatePoolItem({
					key: 'pageActive',
					val: true
				})
				// this.$refs.open_location_info.mShow = false
				this.$util.showLoading()
				let param = this.$util.deepCopy(this.param)
				param.lng = lng
				param.lat = lat
				param.di_order = 0 // 1距离近 2距离远
				param.pr_order = 0 // 1价格高 2价格低
				param.type = 0
				param.order_type = 0
				this.updatePoolItem({
					key: 'param',
					val: param
				})
				this.updatePoolItem({
					key: 'orderTypeIndex',
					val: 1
				})
				if (lat && lng) {
					await this.getList(1)
					// #ifdef APP-PLUS
					this.$refs.open_location_info.pShow = false
					// #endif
				} else {
					this.updatePoolItem({
						key: 'list',
						val: {
							data: [],
							last_page: 1,
							current_page: 1
						}
					})
					this.loading = false
				}
				this.$util.hideAll()
			},
			async toResetUtilLoca() {
				// #ifdef APP-PLUS
				let {
					lat: locaLat = 0
				} = this.location
				if (!locaLat && this.pageActive) {
					let {
						lng = 0,
							lat = 0,
							address = ''
					} = await this.$util.getUtilLocation(true)
					if (!address) {
						console.log(this.location, '========> 通过key获取地理位置')
						await this.$util.getMapInfo()
					}
					if (!lat && !lng) return
					// #ifdef APP-PLUS
					this.$refs.open_location_info.pShow = false
					// #endif

					this.$util.showLoading()
					let param = this.$util.deepCopy(this.param)
					param.lng = lng
					param.lat = lat
					param.di_order = 0 // 1距离近 2距离远
					param.pr_order = 0 // 1价格高 2价格低
					param.type = 0
					param.order_type = 0

					this.updatePoolItem({
						key: 'param',
						val: param
					})
					this.updatePoolItem({
						key: 'orderTypeIndex',
						val: 1
					})
					await Promise.all([this.getTypeList(), this.getList(1)])
					this.$util.hideAll()
				}

				// #endif
			},
			initRefresh() {
				this.getCoachInfo()
				this.getAcceptCount()
				let {
					lat,
					lng
				} = this.location
				if (lat && lng) {
					this.$util.showLoading()
					this.getList(1)
				}
			},
			async getAcceptCount() {
				let allCount = await this.$api.pool.getAcceptCount()
				this.allCount = allCount
			},
			async chooseLocation() {
				await this.$util.checkAuth({
					type: 'userLocation'
				})
				// console.log(this.location , '========> location')
				// let {
				// 	lat,
				// 	lng
				// } = this.location
				// let param = {
				// 	latitude: lat,
				// 	longitude: lng
				// }
				// let [err, loca_data] = await uni.chooseLocation(param)
				// console.log(loca_data , '========> loca_data')

				let location = await this.$util.chooseLocation(1)
				let {
					lat,
					lng
				} = location
				if (!lat) return
				let param = await this.$util.deepCopy(this.param)
				param.lng = lng
				param.lat = lat
				this.updatePoolItem({
					key: 'param',
					val: param
				})
				this.$util.showLoading()
				await this.getList()
			},
			async getList(page = 0) {
				if (page) {
					let param = this.$util.deepCopy(this.param)
					param.page = page
					this.updatePoolItem({
						key: 'param',
						val: param
					})
				}
				let {
					list: oldList,
					param,
				} = this

				try {
					await this.getWaitOrderList(param)
					this.loading = false
					this.$util.hideAll()
				} catch (e) {
					this.loading = false
					this.$util.hideAll()
				}
			},
			refuseOrder(item) {
				uni.showModal({
					title: '提示',
					content: '是否拒绝接单',
					success: function(res) {
						if (res.confirm) {
							this.$util.goUrl({
								openType: 'call',
								url: this.coachInfo.service_tel
							})
						}
					}
				})

			},
			async orderChange(index) {
				if (this.location.address.indexOf(this.coachInfo.city) == -1) {
					this.$util.showToast({
						title: '不能跨市接单'
					})
					return
				}
				if (!this.coachInfo.id_code) {
					let [res_del, {
						confirm
					}] = await uni.showModal({
						content: `请补全信息且审核通过再接单`,
					})
					if (confirm) {
						this.$util.goUrl({
							url: `/user/pages/service-apply`
						})
						return
					}
					if (!confirm) return;
				}

				uni.showModal({
					title: '提示',
					content: '是否确认接单',
					success: async function(res) {
						if (res.confirm) {

							let {
								id
							} = this.list.data[index]

							this.$util.showLoading()
							let data = ''
							if (this.orderTypeIndex == 1) {
								data = await this.$api.order.updateOrder({
									id,
									status: 3
								})
							} else if (this.orderTypeIndex == 2) { // 需求订单 操作 6接单 7出发 8到达 9开始服务 10服务完成
								data = await this.$api.demand.updateOrderStatus({
									id,
									status: 6
								})
							}
							this.$util.hideAll()
							if (data && data.err_code == 'kezhi') {
								let [res_del, {
									confirm
								}] = await uni.showModal({
									content: data.err_msg,
								})
								if (confirm) {
									this.$util.goUrl({
										url: `/user/pages/wallet/index`
									})
									return
								}
								if (!confirm) return;
							}

							this.$util.showToast({
								title: '接单成功'
							})
							this.initRefresh()
							this.updateHomeItem({
								key: 'pageActive',
								val: false
							})


						}

					}

				})



			},
			handerTabChange(index) {
				this.updatePoolItem({
					key: 'activeIndex',
					val: index
				})
				uni.pageScrollTo({
					scrollTop: 0
				})
				let key = {
					0: 'showDistance',
					1: 'showServer',
					2: 'showPrice',
					3: 'showDemand'
				}
				this[key[index]] = true
			},
			handerTypeChange() {
				this.$refs.screen_all.open()
			},
			selectConfirm(e, type) {
				console.log(e, type)
				if (type == 'ordertype') { // 需求订单
					this.updatePoolItem({
						key: 'orderTypeIndex',
						val: e.value
					})
					this.$util.showLoading()
					this.getList(1)
				} else {
					let param = this.$util.deepCopy(this.param)
					param.di_order = 0
					param.pr_order = 0
					if (type == 'type') {
						param[type] = e.value[1] ? e.value[1] : e.value[0]
					} else {
						param[type] = e.value
					}
					this.updatePoolItem({
						key: 'param',
						val: param
					})
					this.$util.showLoading()
					this.getList(1)
				}
			},
			goDetail(id) {
				if (this.orderTypeIndex == 1) {
					this.$util.goUrl({
						url: `/user/pages/pool/detail?id=${id}`
					})
				} else if (this.orderTypeIndex == 2) {
					this.$util.goUrl({
						url: `/demand/pages/pool/detail?id=${id}`
					})
				}
			},
			// 接单
			async changeWork() {
				let {
					is_work = 0
				} = this.coachInfo
				this.$util.showLoading()
				await this.$api.home.updateWork({
					is_work: is_work == 0 ? 1 : 0
				})
				let coachInfo = this.$util.deepCopy(this.coachInfo)
				coachInfo.is_work = is_work == 0 ? 1 : 0
				this.updateUserItem({
					key: 'coachInfo',
					val: coachInfo
				})
				// this.getCoachInfo()
				if (is_work == 0) {
					let param = this.$util.deepCopy(this.param)
					param.di_order = 0
					param.pr_order = 0
					param.page = 1
					param.type = 0
					await this.updatePoolItem({
						key: 'param',
						val: param
					})
					if (!this.location.lat) {
						let {
							lng = 0,
								lat = 0,
								address = ''
						} = await this.$util.getUtilLocation(true)
						if (!address) {
							console.log(this.location, '========> 通过key获取地理位置')
							await this.$util.getMapInfo()
						}
					}
					if (this.location.lat) {
						this.getList(1)
					}
				}
				this.$util.hideAll()
				this.$util.showToast({
					title: '操作成功'
				})
			},
			changeType(index) {
				this.params.orderTypeIndex = index
			},
			checkConfirm(value, type) {
				this.params.di_order = 0
				this.params.pr_order = 0
				this.params[type] = value
				this.params = params
			},
			toConfirm() {
				this.updatePoolItem({
					key: 'orderTypeIndex',
					val: this.params.orderTypeIndex
				})
				let param = this.$util.deepCopy(this.param)
				console.log(param, '========> toConfirm')
				for (let key in this.params) {
					if (key != 'orderTypeIndex') {
						param[key] = this.params[key]
					}
				}
				this.updatePoolItem({
					key: 'param',
					val: param
				})
				this.$util.showLoading()
				this.list.data = []
				this.getList(1)
				this.$refs.screen_all.close()
			},
			toReset() {
				this.params = {
					di_order: 0, // 1距离近 2距离远
					pr_order: 0, // 1价格高 2价格低
					type: 0,
					order_type: 0,
					orderTypeIndex: 1
				}
				this.toConfirm()
			},
			async toOpenLocation() {
				await this.$util.checkAuth({
					type: 'userLocation',
					checkApp: true
				})
				// #ifdef MP-WEIXIN 
				this.initIndex()
				// #endif
			},

			mapNavigaion(address) {

				this.$util.encodeAddress(address).then(data => {
					this.$util.mapNavigation(data.latitude, data.longitude,address)
				})
			}
		},
	}
</script>


<style lang="scss">
	.pages-technician {
		.order-name {
			width: 180rpx;
		}

		.order-btn {
			width: 207rpx;
			height: 80rpx;
		}

		.w-100 {
			width: 100%;
		}

		.order-type {
			// height: 56rpx;
			border: 1px solid;
		}

		.type-item {
			min-width: 112rpx;
			height: 60rpx;
			border-radius: 60rpx;
			color: #778498;
			border: 1px solid #DDDDDD;
		}

		.count-number {
			min-width: 30rpx;
			height: 30rpx;
			border-radius: 30rpx;
			right: -10rpx;
			top: -26rpx;
		}
	}

	.locationContainer {
		margin-right: 0px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.location {
			width: 30px;
			height: 30px;
		}
	}
</style>